// Copyright 2010 Alexandre Tristan St-Cyr <tristan.stcyr@gmail.com>

package com.codeplex.loadjava.model;


public class Field {
	private JavaClass declaringClass;
	
	private String name;
	
	private TypeReference type;
	
	public Field(JavaClass declaringClass, String name, TypeReference type) {
		this.declaringClass = declaringClass;
		this.name = name;
		this.type = type;
	}
	
	public JavaClass getDeclaringClass()
	{
		return this.declaringClass;
	}
	
	public String getName()
	{
		return this.name;
	}
	
	public TypeReference getType()
	{
		return this.type;
	}
	
	@Override
	public int hashCode()
	{
		return (this.getMangledName()).hashCode();
	}
	
	@Override
	public boolean equals(Object o)
	{
		if (!Field.class.isInstance(o))
			return false;
		Field other = (Field)o;
		return this.declaringClass.equals(other.declaringClass)
			&& this.name.equals(other.name)
			&& this.type.equals(other.type);
	}
	
	private String getMangledName()
	{
		return this.declaringClass + "." + this.name + 
			"." + this.type.getDescriptor();
	}
	
	@Override
	public String toString()
	{
		return this.getMangledName();
	}
}
